﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.IO;
using System.Collections.ObjectModel;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;

namespace RelyingPartyService
{
	public class RPServiceTest1 : IRPServiceTest1, IRPServiceTest2, IRPServiceTest3, IRPServiceTest4
    {
        public string Test1()
        {
            return "Test1";
        }

        public string Test2()
        {
			return "Test2:" + GetEMail();
		}
		public string Test3()
		{
			return "Test3 Authorized!";
		}
		public string Test4()
		{
			return "Test4 Authorized!";
		}
		private string GetEMail()
		{
			AuthorizationContext authContext = OperationContext.Current.ServiceSecurityContext.AuthorizationContext;
			List<ClaimSet> claimsets = new List<ClaimSet>(authContext.ClaimSets);
			ClaimSet myClaimSet = claimsets.Find((Predicate<ClaimSet>)delegate(ClaimSet target)
			{
				return target.FindClaims(ClaimTypes.Email, Rights.PossessProperty).Count() > 0;
			});
			return myClaimSet.FindClaims(ClaimTypes.Email, Rights.PossessProperty).First().Resource.ToString();
		}
	}
}
